//
//  File.swift
//  mm
//
//  Created by mac on 16/4/6.
//  Copyright © 2016年 Qingke. All rights reserved.
//

import UIKit

class Beauty:NSObject,NSCoding {
    var name : String
    var photo : UIImage?
    var ranting : Int
    
    static let DocumentDirectory = NSFileManager().URLsForDirectory(.DocumentDirectory, inDomains: .UserDomainMask).first!
    static let ArchiveURL = DocumentDirectory.URLByAppendingPathComponent("beauty")
    
    init? (name :String,photo:UIImage?,ranting:Int) {
        self.name = name
        self.photo = photo
        self.ranting = ranting
        
        super.init()
        if name.isEmpty  || ranting < 0 {
            return nil
        }
    }
    
    // ya suo wen jian
    func encodeWithCoder(aCoder: NSCoder) {
        aCoder.encodeObject(name ,forKey : "name")
        aCoder.encodeObject(photo,forKey: "photo")
        aCoder.encodeInteger(ranting,forKey: "ranting")
        
    }
    // du qu wen jian
    required convenience init?(coder aDecoder:NSCoder) {
        let name = aDecoder.decodeObjectForKey("name") as! String
        let photo = aDecoder.decodeObjectForKey("photo") as? UIImage
        let ranting = aDecoder.decodeIntegerForKey("ranting")
        
        self.init(name:name,photo:photo,ranting:ranting)
    }
}

